package top.yangyitao.lockManager.aop;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.MethodParameter;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
import top.yangyitao.lockManager.lock.LockManager;

@Slf4j
@ControllerAdvice(basePackages = {"top.yangyitao.controller","top.yangyitao.exception.handler"})
public class ResultHandlerAdvice implements ResponseBodyAdvice<Object> {
    @Autowired
    LockManager lockManager;
    //只负责用户线程
    @Override
    public boolean supports(MethodParameter returnType, Class converterType) {
        return true;
    }

    @Override
    public Object beforeBodyWrite(Object o, MethodParameter methodParameter, MediaType mediaType, Class<? extends HttpMessageConverter<?>> aClass, org.springframework.http.server.ServerHttpRequest serverHttpRequest, org.springframework.http.server.ServerHttpResponse serverHttpResponse) {
        log.info("lockManager: clear all lock");
        lockManager.retireAll();
        return o;
    }
}



